/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.testis.gui.mvc.utilities;

import org.testis.orm.testbed.refined.TestBedItem;
import org.testis.utils.tree.TbedMutableTreeNode;
import java.awt.Component;
import java.util.Locale;
import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.JTree;
import javax.swing.tree.DefaultTreeCellRenderer;

/**
 *
 * @author selcuk
 */
public class TbedNodeRenderer extends DefaultTreeCellRenderer {

    @Override
    public Component getTreeCellRendererComponent(JTree tree, Object value,
            boolean sel,
            boolean expanded,
            boolean leaf, int row,
            boolean hasFocus) {
        super.getTreeCellRendererComponent(tree, value, sel, expanded, leaf,
                row, hasFocus);
        TbedMutableTreeNode tbedNode = (TbedMutableTreeNode) value;

        Object object = tbedNode.getUserObject();
        if (object instanceof TestBedItem) {
            String imageName = tbedNode.getTypeName().toLowerCase(Locale.ENGLISH);
            imageName += ".png";
            ImageIcon imageIcon = createImageIcon("images/testbed/" + imageName);
            setIcon(imageIcon);
        } else if (object instanceof String) {
            Icon imageIcon = super.getOpenIcon();
            setIcon(imageIcon);
        }
        return this;
    }

    public static ImageIcon createImageIcon(String path) {
        return ImageFactory.instance().createImageIcon(path);
    }
}
